<template>
  <div class="login">
    <div class="login-content">
      <h1 class="login-title">大学生选报系统</h1>
      <div class="demo-input-suffix">
      请输入用户名：
      <el-input
      maxlength=12
        placeholder="请输入用户名"
        prefix-icon="el-icon-user"
        v-model="username"
      >
      </el-input>
    </div>
    <div class="demo-input-suffix">
      请输入密码：
      <el-input placeholder="请输入密码" prefix-icon="el-icon-view" v-model="password" show-password>
    </el-input>
    </div>
    <div class="login-btn">

     <el-button plain @click="login" >登陆</el-button>
    </div>
    </div>
    
  </div>
</template>

<script>
import Api from "../assets/js/api";
export default {
  
  data() {
    return {
      username: "",
      password: "",
    };
  },
  methods:{
    login(){
      if (this.username==""||this.password=="") {
        this.$message({
              message: "请先填写用户名或密码",
              type: "error",
              center:true
            });
            return
      }else{
        this.$http({
          url: Api.authentication, //接口
          method: "POST", //请求方式 默认get
          data: {
            username:this.username,
            password:this.password
          } // data数据
        }).then(res => {
          console.log(res.data);
          if (res.data.status == 0) { //账号密码正确
           sessionStorage.setItem("token", res.data.data);//存数据
          //  sessionStorage.getItem("token");//取数据
          //  const a=sessionStorage.getItem("token");
          //  console.log(a);
           
          //  sessionStorage.removeItem("key");//删数据
            this.$router.push("/recruit");
            this.$message({
              message: "登录成功",
              type: "success"
            });
          } else {
            this.$message({
              message: "账号或密码错误",
              type: "error",
              center:true
            });
          }
        });
      }
    }
  }
};
</script>

<style>
*{
  padding: 0;
  margin: 0;
}
.login{
  background:#F2F6FC no-repeat right top url('https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1591787842614&di=f0224bef6cede052755c5b908eaacd3a&imgtype=0&src=http%3A%2F%2Fh.hiphotos.baidu.com%2Fzhidao%2Fpic%2Fitem%2Fcefc1e178a82b901650e251a728da9773912ef7c.jpg');
  width: 100vw;
  height: 100vh;
  /* overflow: hidden; */
  position: relative;
}
/* .login-title{
  position: absolute;
  top: 116px;
  left: 20%;
  color: #F2F6FC;
} */
.login-content{
  box-shadow: #C0C4CC 3px 5px 10px;
  color: #606266;
  border-radius: 10px;
  padding:30px 20px;
  width: 400px;
  height: 300px;
  position: absolute;
  top: 116px;
  left: 60%;
  /* box-sizing: border-box; */
  background-color: #fff;
}
.login-title{
  text-align: center;
}
.demo-input-suffix{
  margin-top: 30px;
}
.login-btn{
  text-align: center;
  line-height: 100px;
  width: 100%;
}
.login-btn button{
  width: 100%;
}
</style>
